#include <hidef.h> /* for EnableInterrupts macro */
#include "derivative.h" /* include peripheral declarations */
#include "main header.h"
#include "display.h"
#include "system.h"
#include "color.h"
#include "string.h"
#include "serial.h"
#include "sma.h"
#include "stdio.h"
#include "key.h"
#include <mc9s08ll64.h>

#ifdef __cplusplus
extern "C"
#endif
void MCU_init(void); /* Device initialization function declaration */



void main(void) {
  uint8_t c = 100,c1 = 100,c2 = 100;
  MCU_init();	/* call Device Initialization */
  /* include your code here */
  Sys_Init(&Sys);
  // segment test
  DisplayAllOff();
  DisplayAllOn();
  delay_1sec();
  // version display
  DisplayAllOff();
  Display_String("v1.00.00", &Sys.Annuc);
  Display_Mode('0');
  delay_1sec();
  // Start displaying welcome message that is initialized in system 
  Sys.bRdy = 1;
  
  for(;;) 
  {
    /* __RESET_WATCHDOG(); By default COP is disabled with device init. When enabling, also reset the watchdog. */
	  Process_Serial_Data(&Sys.Ser, &Sys.Time);
	  if (c != Sys.Color[0])
	  {
		  process_red(Sys.Color[0]);
		  c = Sys.Color[0];
	  }
	  if (c1 != Sys.Color[1])
	  {
		  process_green(Sys.Color[1]);
		  c1 = Sys.Color[1];		 
	  }
	  if (c2 != Sys.Color[2])
	  {
		  process_blue(Sys.Color[2]);
		  c2 = Sys.Color[2];
	  }
	  if (Sys.Time.bOn == 0)
	  {
		  Sys_Reset(&Sys);
		  Sys.Time.bOn = -1;
	  }
	  scan_keybrd(&Sys.keybrd);
	  process_keybrd_intent();
  } /* loop forever */
  /* please make sure that you never leave main */
}
